package com.example.weather.today

import androidx.lifecycle.SavedStateHandle
import com.example.library_base.base.BaseViewModel
import com.example.library_base.util.LogUtil
import com.example.library_base.util.TransformUtil
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class TodayWeatherViewModel @Inject constructor(
    private val repository: TodayWeatherRepository,
    private val savedStateHandle: SavedStateHandle
): BaseViewModel<TodayWeatherModel>()  {

    companion object{
        const val TAG = "TodayWeatherViewModel"
    }

    //查询今天的天气状况
    fun searchTodayWeather(inputModel: TodayWeatherInputModel){
        val map = mutableMapOf<String, Any>()
        map["city"] = inputModel.city
        map["type"] = inputModel.type

        LogUtil.debug(TAG, inputModel.toString())

        launchUI {
            val result = repository.searchTodayWeather(map)
            result?.let {
                val todayWeatherModel = TransformUtil.transAnyToObj<TodayWeatherModel>(it)
                LogUtil.debug(TAG, todayWeatherModel.toString())
                setModelLiveData(todayWeatherModel)
            }
        }
    }
}